﻿@{
    Layout = "~/Views/Shared/_detail.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
    <link href="/SiteUI/Trade/DeliveryBill.css" rel="stylesheet" />
}
<title>发货单</title>

<div class="row" id="pagePath">
    <div class="col-lg-6" obj-auth="true" obj-role="saler" obj-org="">
        <a class="strong" href="/Sale/Delivery">销售：发货管理</a>&nbsp;>&nbsp;<a href="#">发货单详情</a>
    </div>
    <a obj-status="Active|Completed" id="lnkDeliveryPrnt" target="_blank" class="LinkTo" href="/Trade/DeliveryBillPrnt?oid="><i class="soicon icon-localprintshop"></i>打印预览</a>
</div>

<div class="row" id="orderHead">
    <div class="col-lg-4">
        <h4>交易编号：<a class="LinkTo" href="/Trade/OrderDetail?oid=" id="oh-id">00001</a></h4>
    </div>
    <div class="col-lg-4">
        <h4>发货单号：<a class="LinkTo" id="oh-dlvid">00001</a></h4>
    </div>
    <div class="col-lg-4">
        <h4>状态:<span id="oh-status" class="pendding"><i>未确认</i></span></h4>
    </div>
</div>

<!--发货单详情-->
<div class="InfoSection row expand">
    <div class="InfoSectionTitle">
        交易信息
        <i class="soicon "></i>
    </div>
    <div class="InfoSectionBody col-lg-12" id="tradeInfo">
        <div class="row ti-body">
            <div class="col-lg-4">
                <h5>联系人信息</h5>
                <div class="DataField">
                    <span class="df-title">采&nbsp;&nbsp;购&nbsp;&nbsp;商：</span>
                    {{#if(d.client_realname){ }}
                    <span class="df-value"><a href="#" class="Company certificated" objid="{{d.client_idstr}}">{{d.client_realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#" class="Company no-certificated">{{d.invoiceheading}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</span>
                    {{#if(d.buyer){ }}
                    <span class="df-value"><a href="#" class="People certificated" objid="{{d.buyer.idstr}}">{{d.buyer.realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#" class="People no-certificated">{{d.src_buyer}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联系方式：</span>
                    <span class="df-value">{{d.buyer_phone||d.src_buyerphone}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">供&nbsp;&nbsp;应&nbsp;&nbsp;商：</span>
                    {{#if(d.supplier_idstr){ }}
                    <span class="df-value"><a href="#">{{d.supplier_realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#">{{d.src_supplier}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</span>
                    {{#if(d.saler_idstr){ }}
                    <span class="df-value"><a href="#" class="People certificated">{{d.saler.realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#" class="People no-certificated">{{d.src_saler}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联系方式：</span>
                    <span class="df-value">{{d.saler_phone||d.src_salerphone}}</span>
                </div>
            </div>
            <div class="col-lg-4">
                <h5>交付信息</h5>
                <div class="DataField">
                    <span class="df-title">收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                    <span class="df-value">
                        <span>{{d.consignee_displayname}}</span>
                        <span>{{d.consignee_phone}}</span>
                    </span>
                </div>
                <div class="DataField">
                    <span class="df-title">施工单位：</span>
                    <span class="df-value">
                        <span>{{d.constructor}}</span>
                    </span>
                </div>
                <div class="DataField">
                    <span class="df-title">交付方式：</span>
                    <span class="df-value">{{d.deliverymode}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">送货地址：</span>
                    <span class="df-value">{{d.src_dlvaddress}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">送货时间：</span>
                    <span class="df-value">{{d._dlvDate}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">质保条件</span>
                    <span class="df-value">{{d.qualityguarantee}}</span>
                </div>
            </div>
            <div class="col-lg-4">
                <h5>执行信息</h5>
                <div class="DataField">
                    <span class="df-title">发&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                    <span class="df-value">
                        <span>{{d.dlvcreater}}</span>
                    </span>
                </div>
                <div class="DataField">
                    <span class="df-title">发货时间：</span>
                    <span class="df-value">{{d.dlvtime}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                    <span class="df-value">{{d.rcpter||'-'}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">收货时间：</span>
                    <span class="df-value">{{d.rcpttime||'-'}}</span>
                </div>
            </div>
        </div>
        <div class="row">
            <h5>其他信息</h5>
            {{#if(d.src_orderserial){ }}
            <div class="DataField">
                <span class="df-title">客户订单：</span>
                <span class="df-value">{{d.src_orderserial}}{{d.src_orderversion}}</span>
            </div>
            {{#} }}
            <div class="DataField">
                <span class="df-title">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</span>
                <span class="df-value">{{d.memo}}</span>
            </div>
        </div>
    </div>
</div>

<!--发货单明细-->
<div class="InfoSection row expand" id="orderItems">
    <div class="InfoSectionTitle col-lg-12">
        发货明细
        <i class="soicon "></i>
    </div>
    <div class="InfoSectionBody col-lg-12">
        <div class="gridtable modenStyle">
            <div class="grid-row headrow">
                <div class="grid-col start" style="width:25%">产品</div>
                <div class="grid-col" style="width:30%;left:25%">型号&规格</div>
                <div class="grid-col" style="width:10%;left:55%">数量</div>
                <div class="grid-col" style="width:10%;left:65%">本单发货量</div>
                <div class="grid-col" style="width:10%;left:75%">实收数量</div>
                <div class="grid-col end" style="width:15%;left:85%">备注</div>
            </div>
            <div class="grid-body">
                <div class="grid-row order-item-tpl">
                    <div class="grid-col start order-item-product" style="width:25%"></div>
                    <div class="grid-col order-item-describe" style="width:30%;left:25%"></div>
                    <input disabled="disabled" class="grid-col order-item-count" style="width:10%;left:55%"/>
                    <input class="grid-col order-item-thisdelivery"disabled="disabled" style="width:10%;left:65%"/>
                    <input type="number" obj-auth="true" obj-role="consignee|buyer" obj-status="Active|Pending" execute="disable" class="grid-col order-item-receipt" style="width:10%;left:75%"/>
                    <input obj-auth="true" obj-role="consignee|buyer" obj-status="Active|Pending" execute="disable" class="grid-col end order-item-remark"style="width:15%;left:85%"/>
                </div>
            </div>
        </div>
    </div>   
</div>
<div class="row">
    <div class="col-lg-1">
        <h5>发货备注：</h5>
    </div>
    <div class="col-lg-11">
        <div id="dlv-memo"></div>
    </div>
</div>
<div class="row">
    <div obj-auth="ture" obj-org="supplier_deptidstr" class="col-lg-2 col-lg-offset-10 button btn-risky btn-lite" id="btnAbort">作废</div>
    <div obj-auth="true" obj-role="consignee" obj-status="Active" class="col-lg-2 col-lg-offset-10 button" id="btnReceipt">收货确认</div>
</div>

<script src="/LiberUI/Scripts/laytpl.js"></script>
<script src="/SiteUI/res_sobiz.js"></script>
<script>
    var dlvBill = {};
    var order = {};
    var ViewDB = {
        tplOrderInfo:null,
        btnReceipt:null,
        GetDeliveryEnd: function (rtn) {
            if (rtn.IsPositive) {
                dlvBill = rtn.Data;
                dlvBill.supplier_deptidstr = order.supplier_deptidstr;
                order = dlvBill.order;
                //#region 处理订单状态信息
                if (dlvBill.status == 'Active') {
                    ViewDB.btnReceipt.vl("收货确认").enable();
                }
                else {
                    ViewDB.btnReceipt.vl("已收货").disable();
                }

                if (dlvBill.status == 'Pending' || dlvBill.status == 'Active') {
                    ViewDB.btnAbort.vl("作废").show();
                }
                else {
                    $("#lnkDeliveryPrnt").remove();
                    ViewDB.btnAbort.dispose();
                }

                $("#lnkDeliveryPrnt").attr("href", "/Trade/DeliveryBillPrnt?oid="+dlvBill.idstr);
                $("#oh-id").vl(order.idstr).attr("href","/Trade/OrderDetail?oid="+order.idstr);
                $("#oh-dlvid").vl(dlvBill.idstr);
                $("#oh-status").addClass(dlvBill.status);
                $("#oh-status").vl("<i></i>" + res_sobiz.var.Sale.Delivery[dlvBill.status]);

                order.buyer_email = order.buyer_email || "-";
                order.saler_email = order.saler_email || "-";
                order.consignee_displayname = order.src_consignee || order.consignee_realname;
                order.consignee_phone = order.consignee_phone || order.src_consigneephone;
                order._dlvDate = new Date(order.src_deliverydate || order.deliverydate).toString();
                order.dlvcreater = dlvBill.dlvcreater||'-';  //发货单创建人
                order.dlvtime = new Date(dlvBill.createtime).format("yyyy-MM-dd HH:mm:ss");
                if (order.src_subconstuctor) {
                    order.src_constructor += "(" + order.src_subconstuctor + ")";
                }
                order.constructor = order.src_constructor || "-";


                //#endregion

                var ti = ViewDB.tplOrderInfo.render(order);
                $("#tradeInfo").append(ti).fadeIn();

                ViewDB.btnReceipt.show();
                ViewDB.renderOrderMX();

                $("#dlv-memo").vl(dlvBill.memo||"");

                View.CheckAuthor(order);
                $("#pagePath").fadeIn();
            }
        },
        renderOrderMX:function(){
            //#region 处理发货单明细
            if (dlvBill.deliverymx) {
                var tpl = $(".order-item-tpl").eq(0);
                dlvBill.deliverymx.forEach(function (i) {
                    var row = tpl.clone();
                    var cols = row.children(".grid-col");
                    var b = $("<div class='DataField'>");
                    b.append($("<span class='df-title'>品牌：</span>"));
                    b.append($("<span class='df-value'>").vl(i.brand || '-'));

                    var p = $("<div class='DataField'>");
                    p.append($("<span class='df-title'>产品：</span>"));
                    p.append($("<span class='df-value'>").vl(i.product || '-'));

                    var c = $("<div class='DataField'>");
                    c.append($("<span class='df-title'>编码：</span>"));
                    c.append($("<span class='df-value'>").vl(i.src_code || '-'));

                    var m = $("<div class='DataField'>");
                    m.append($("<span class='df-title'>型号：</span>"));
                    m.append($("<span class='df-value'>").vl(i.model || '-'));

                    var s = $("<div class='DataField'>");
                    s.append($("<span class='df-title'>规格：</span>"));
                    s.append($("<span class='df-value'>").vl(i.src_specification || '-'));

                    cols.eq(0).append(b).append(p).append(c);
                    cols.eq(1).append(m).append(s);
                    cols.eq(2).vl(i.count + "(" + i.unit + ")");
                    cols.eq(3).vl(i.todelivery + "(" + i.unit + ")");
                    if (dlvBill.status == 'Completed'||dlvBill.status=='Pending') {
                        cols.eq(4).vl(i.receipt);
                        cols.eq(5).vl(i.dlv_remark);
                    }
                    row.appendTo(".grid-body").show();
                    i.$row = row;
                });
            }
            //#endregion
        },
        onInsecClick: function (ev) {
            $(this).parent(".InfoSection").toggleClass("expand");
        },
        Receipt: function (ev) {
            var rcptMX = [];
            dlvBill.deliverymx.forEach(function (i) {
                var receipt = i.$row.children(".grid-col").eq(4);
                var rmrk = i.$row.children(".grid-col").eq(5);
                var rcptCount = parseFloat(receipt.vl());
                rcptMX.push(
                    {
                        "ordermxidstr":i.idstr,
                        "dlvmxidstr": i.dlvmxidstr,
                        "receipt": rcptCount>=0?rcptCount:0,
                        "remark":rmrk.vl()||""
                    }
                );
            })

            //发送
            $.post("/Purchase/ReceiptDelivery", { "rcptMX": GetXML({ "item": rcptMX, "dlvid": dlvBill.idstr,"orderid":order.idstr }) }, function (rtn) {
                if (rtn.IsPositive) {
                    window.history.go(0);
                }
                else {
                    error("操作失败", ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
                }

            });
        },
        Abort: function (ev) {
            ViewDB.btnAbort.disable();
            dlgConfirmAbort = new LiberUI.Dialoger()
                                    .Title("作废")
                                    .Content($("<div style='width:300px'><h4>您确定要作废此发货单吗？</h4></div>"))
                                    .BtnEnter("确定", "", function () {
                                        $.post("/Sale/AbortDelivery", { objid: dlvBill.idstr }, function () {
                                            window.location = window.location;
                                        })
                                    })
                                    .BtnEsc("放弃", "", function () {
                                        ViewDB.btnAbort.enable();
                                        dlgConfirmAbort.dispose();
                                    })
                                    .update()
                                    .show();
        }
    }
    $(function () {
        var oid = getUrlParam("oid");
        $("body").on("UserReady", function () {
            $.getJSON("/Trade/GetDelivery", { "oid": oid }, ViewDB.GetDeliveryEnd);
        })

        $(".InfoSectionTitle").on("click", ViewDB.onInsecClick);

        ViewDB.tplOrderInfo = laytpl($("#tradeInfo")[0].innerHTML);
        $("#tradeInfo").vl("");

        ViewDB.btnReceipt = new LiberUI.Button("#btnReceipt")
                                       .on("LCclick", ViewDB.Receipt);
        ViewDB.btnAbort = new LiberUI.Button("#btnAbort")
                                     .hide()
                                     .on("LCclick", ViewDB.Abort);
    })
</script>

